/*<!-- saved from url=(0013)about:internet -->*/
//*** Initializations

var month = new Array("January","February","March","April","May","June",
"July","August","September","October","November","December");

var date = new Date();
var currYear = date.getFullYear();
var year = new Array(currYear-18-1900);
var j=0;
for(i=1900;i<currYear+1-18;i++)
{
	year[j]=i;
	j++;
}

var day = new Array(32);

for(i=1;i<day.length;i++)
	day[i]=i;

var job = new Array("Software Engineering", "Electrical Engineering", "Biotechnology Engineering");


//Adds an option to a select box
function addOption(selectbox,text,value)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

//Adds all appropriate days, months and years as Date of Birth options
function addOptions_list() {

	//Adding all month options
	for (var i=0; i < month.length; ++i){
	
	addOption(document.forms["myForm"]["month"], month[i], month[i]);
	}
	
	//Adding all year options
	for(var i=0; i< year.length; ++i) {
	
	addOption(document.forms["myForm"]["year"], year[i], year[i]);
	
	}
	
	//Adding all day options
	for(var i=1; i< day.length; ++i) {
	
	addOption(document.forms["myForm"]["day"], day[i], day[i]);
	
	}
	
	for(var i=0; i<job.length; ++i) {
		
	addOption(document.forms["myForm"]["job"], job[i], job[i]);
	}
	

} 

//Function checks if a string contains any special characters (string is not a word)
//Returns - 'true' if special char was found in String (not word), 'false' - otherwise
function notAword(str)
{
	return /[^a-zA-Z]/.test(str);
}


//isOK = true - Form is filled out correctly
//isOK = false - Form is filled out incorrectly
var isOK = true;


//First name validation
function val_fname() 
{

	var name=document.getElementById("fname").value;

	if (name==null || name=="")
	{
		document.getElementById("firstnameerror").style.visibility = "visible";
		isOK = false;
	}
	else if(notAword(name))
	{
		document.getElementById("firstnameerror").style.visibility = "visible";
		isOK = false;
	}
	else
	{
		document.getElementById("firstnameerror").style.visibility = "hidden";
	}

}

//Last name validation
function val_lname() 
{

	var lastname=document.getElementById("lname").value;
	if (lastname==null || lastname=="")
	{
		document.getElementById("lastnameerror").style.visibility = "visible";
		isOK = false;
	}
	else if(notAword(lastname))
	{
		document.getElementById("lastnameerror").style.visibility = "visible";
		isOK = false;
	}
	else
	{
		document.getElementById("lastnameerror").style.visibility = "hidden";
	}


}

//ID validation
function val_id()
{

	var identifier=document.getElementById("id").value;
	if (identifier==null || identifier=="")
	{
		document.getElementById("iderror").style.visibility = "visible";
		isOK = false;
	}
	else if(identifier.length!=9)
	{
		document.getElementById("iderror").style.visibility = "visible";
		isOK = false;
	}
	else if(isNaN(identifier))
	{
		document.getElementById("iderror").style.visibility = "visible";
		isOK = false;
	}
	else
	{
		document.getElementById("iderror").style.visibility = "hidden";
	}

}

//E-mail validation
function val_email() 
{
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
	var email=document.getElementById("email").value;
	var res=emailPattern.test(email);
	if(res==false)
	{	
		document.getElementById("emailerror").style.visibility = "visible";
		isOK = false;	
	}
	
	else
	{
		document.getElementById("iderror").style.visibility = "hidden";
	}
	
}


//City validation
function val_city() 
{
	var city=document.getElementById("city").value;
	if (city==null || city=="")
	{
		document.getElementById("cityerror").style.visibility = "visible";
		isOK = false;
	}
	else if(notAword(city))
	{
		document.getElementById("cityerror").style.visibility = "visible";
		isOK = false;
	}
	else
	{
		document.getElementById("cityerror").style.visibility = "hidden";
	}
}



function val_zipcode() 
{

	//Zip code validation
	var zip=document.getElementById("zip").value;
	if (zip==null || zip=="")
	{
		document.getElementById("zipcodeerror").style.visibility = "visible";
		isOK = false;
	}
	else if(zip.length!=5)
	{
		document.getElementById("zipcodeerror").style.visibility = "visible";
		isOK = false;
	}

	else if(isNaN(zip))
	{
		document.getElementById("zipcodeerror").style.visibility = "visible";
		isOK = false;
	}
	
	else
	{
		document.getElementById("zipcodeerror").style.visibility = "hidden";
	}

}

//Checks if a string is not a word or number (contains special chars except 'space')
//returns true -  If special characters exist
//returns false - If only letters or digits exist
function notWordorNum(str) 
{	
	return /[^a-zA-Z0-9 ]/.test(str);
}

//Address validation
function val_add() 
{
	var address=document.getElementById("address").value;

	if(notWordorNum(address))
	{
		document.getElementById("addresserror").style.visibility = "visible";
		return false;
		
	}
	else
	{
		document.getElementById("addresserror").style.visibility = "hidden";
	}
	
}

function val_cell()
{
	//cell validation
	var cell=document.getElementById("cell").value;
	if (cell==null || cell=="")
	{
		alert("Cell number must be filled out");
		isOK = false;
	}
	if(cell.length!=10)
	{
		alert("Cell number must have 10 digits");
		isOK = false;
	}
	if(isNaN(cell))
	{
		alert("Cell number must contain digits only");
		isOK = false;
	}

}
function validateForm()
{
	val_fname();
	val_lname();
	val_id();
	val_email();
	val_city();
	val_zipcode();
	val_add();
	

var gender=document.getElementById("gender").value;
var mstatus=document.getElementById("mstatus").value;
var day=document.getElementById("day").value; 
var month=document.getElementById("month").value;
var year=document.getElementById("year").value;//should be YYYYMMDD





//Username validation
var user=document.getElementById("uname").value;
if(user==null || user=="")
{
	alert("Username must be filled out");
	isOK = false;
	
}
//Password validation
var pass=document.getElementById("pass").value;
if (pass==null || pass=="")
{
	alert("Password must be filled out");
	isOK = false;
}

var passconf=document.getElementById("passconfirm").value;
if(passconf==null || passconf=="")
{
	alert("Password confirmation must be filled out");
	isOK = false;
}

if(pass!=passconf)
{
	alert("Password and Password confirm does not match");
	isOK = false;
}

if(isOK==false)
	return false;

}